package com.skzh.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.skzh.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.skzh.common.core.controller.BaseController;
import com.skzh.common.core.domain.AjaxResult;
import com.skzh.common.enums.BusinessType;
import com.skzh.equipment.domain.Drone;
import com.skzh.equipment.service.IDroneService;
import com.skzh.common.utils.poi.ExcelUtil;
import com.skzh.common.core.page.TableDataInfo;

/**
 * 无人机信息Controller
 *
 * @author skzh
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/equipment/drone_info")
public class DroneController extends BaseController {
    @Autowired
    private IDroneService droneService;

    /**
     * 查询无人机信息列表
     */
    @ApiOperation(value = "查询无人机信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:drone_info:list')")
    @GetMapping("/list" )
    public TableDataInfo list(Drone drone) {
        startPage();
        List<Drone> list = droneService.selectDroneList(drone);
        return getDataTable(list);
    }

    /**
     * 导出无人机信息列表
     */
    @ApiOperation(value = "导出无人机信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:drone_info:export')" )
    @Log(title = "无人机信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Drone drone) {
        List<Drone> list = droneService.selectDroneList(drone);
        ExcelUtil<Drone> util = new ExcelUtil<Drone>(Drone. class);
        util.exportExcel(response, list, "无人机信息数据" );
    }

    /**
     * 获取无人机信息详细信息
     */
    @ApiOperation(value = "获取无人机信息详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:drone_info:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(droneService.selectDroneById(id));
    }

    /**
     * 新增无人机信息
     */
    @ApiOperation(value = "新增无人机信息")
    @PreAuthorize("@ss.hasPermi('equipment:drone_info:add')" )
    @Log(title = "无人机信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drone drone) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        drone.setCreateBy(loginUser.getUsername());
        return toAjax(droneService.insertDrone(drone));
    }

    /**
     * 修改无人机信息
     */
    @ApiOperation(value = "修改无人机信息")
    @PreAuthorize("@ss.hasPermi('equipment:drone_info:edit')" )
    @Log(title = "无人机信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drone drone) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        drone.setUpdateBy(loginUser.getUsername());
        return toAjax(droneService.updateDrone(drone));
    }

    /**
     * 删除无人机信息
     */
    @ApiOperation(value = "删除无人机信息")
    @PreAuthorize("@ss.hasPermi('equipment:drone_info:remove')" )
    @Log(title = "无人机信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(droneService.deleteDroneByIds(ids));
    }
}
